<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>前后比较法</title>
</head>
<body>
    
    <script>
        
        {

            // 数组去重之前后比较法

            let ary = [1,2,3,1,2,1,1,2,2,1,4,5,4,4,5,5,4,1,5,4,3,3,2,4,5];

            Array.prototype.unique = function () {
               this.sort((a,b)=>{return a-b});
               for(let i=0;i<this.length;i++){
                    if(this[i+1]===this[i]){
                        this.splice(i,1);
                        i--;
                    }
               }
               return this;
            }


            console.log(ary.unique());
        }
    
    </script>

</body>
</html>